import json
import os
import logging

# 创建日志记录器
def create_logger():
    logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s | 文件:%(filename)s,函数:%(funcName)s')
    return logging


# 加载语言数据
def load_language_data():
    print(os.getcwd())
    json_path = os.path.join(os.path.dirname(__file__), 'language.json')
    if os.path.exists(json_path) and os.path.getsize(json_path) > 0:
        with open(json_path, 'r', encoding='utf-8') as f:
            try:
                language_data = json.load(f)
                return language_data
            except json.JSONDecodeError:
                print("JSONDecodeError: Could not parse the file")
                return {"current_language": "zh"}  # 返回默认值
    else:
        print(f"File {json_path} does not exist or is empty")
        return {"current_language": "zh"}  # 返回默认值

# 写入语言数据
def write_language_data(language_data, key, value):
    language_data[key] = value
    json_path = os.path.join(os.path.dirname(__file__), 'language.json')
    with open(json_path, 'w', encoding='utf-8') as f:
        json.dump(language_data, f, ensure_ascii=False, indent=4)


#################### 以下是载入代码 ####################
language_data = load_language_data()
logging = create_logger()



